package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.TravelAgencyDetail;
import com.example.mountainwalker.service.TravelAgencyService;
import com.example.mountainwalker.service.impl.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mw/travelAgency")
public class TravelAgencyController {

    @Autowired
    private TravelAgencyService travelAgencyService;

    @GetMapping("/list")
    public PageResult<TravelAgencyDetail> getTravelAgencyList(
            @RequestParam(required = false) String travelAgencyName,
            @RequestParam(required = false) String officePhone,
            @RequestParam(required = false) String province,
            @RequestParam(required = false) String city,
            @RequestParam(required = false) String auditStatus,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {

        return travelAgencyService.getTravelAgencyListByCondition(
                travelAgencyName, officePhone, province, city,
                auditStatus, pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public TravelAgencyDetail getTravelAgencyById(@PathVariable Integer id) {
        return travelAgencyService.getTravelAgencyById(id);
    }

    @DeleteMapping("/delete/{id}")
    public int deleteTravelAgencyById(@PathVariable Integer id) {
        return travelAgencyService.deleteTravelAgencyById(id);
    }

    @PostMapping("/batchDelete")
    public int batchDeleteTravelAgency(@RequestBody List<Integer> ids) {
        return travelAgencyService.batchDeleteTravelAgency(ids);
    }

    @PutMapping("/update")
    public int updateTravelAgency(@RequestBody TravelAgencyDetail travelAgencyDetail) {
        return travelAgencyService.updateTravelAgency(travelAgencyDetail);
    }
}